<template>
  <div class="system-disk" ref="systemDisk"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "system-disk",
  props:["sysFiles"],
  data() {
    return {};
  },
  watch: {
    sysFiles(newValue, oldValue) {
      // console.log(newValue, oldValue, 5555);
      this.drawImgFive();
      immediate: true; //打开组件立即侦听 ******
    }
  },
  computed:{
    sysFilesfree(){
      return parseFloat(this.sysFiles[0].free);
    },
    sysFilesused(){
      return parseFloat(this.sysFiles[0].used);
    },
  },
  methods: {
    drawImgFive() {
      let myChart = echarts.init(this.$refs.systemDisk);
      let options = {
        title: {
          text: "系统盘使用率",
          left: "left",
          textStyle: {
            fontSize: 14
          },
        },
        color: [
          "#ee6666", 
          "#DDDDDD",
        ],
        tooltip: {
          trigger: "item"
        },
        legend: {
          orient: "vertical",
          // 距离右边1%
          right: "1%",
          // 小方块的宽高
          itemWidth:20,
          itemHeight:12,
        },
        series: [
          {
            name: "系统盘使用率G",
            type: "pie",
            radius: "50%",
            // 箭头隐藏
            label:{
              show:false
            },
            data: [
              { value: this.sysFilesused, name: "已用" },
              { value: this.sysFilesfree, name: "可用" }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            }
          }
        ]
      };
      myChart.setOption(options);
    },
  },
};
</script>

<style lang="less" scoped>
.system-disk {
  width: 100%;
  height: 100%;
}
</style>
